<template>
  <div class="page-main">
    <a-layout style="height: 100%">
      <a-layout-header
        ><page-title>系统合并策略定义</page-title></a-layout-header
      >
      <a-layout-content>
        <a-form :model="form" layout="vertical" class="form">
          <a-form-item
            field="secretLevelValue"
            label="密级:"
            style="width: 200px"
          >
            <secretLevelSelect
              v-model:model-value="form.secretLevelValue"
              :is-show-clear-tip="true"
              :default-value="form.secretLevelValue"
              @change="change"
            />
          </a-form-item>
        </a-form>
        <a-spin :loading="loading" style="width: 100%">
          <Content ref="conRef" :is-show="isShow" />
        </a-spin>
      </a-layout-content>
      <a-layout-footer
        ><Footer
          :permission-flag="'procurement:require-option:admin-save'"
          @saveData="saveData"
      /></a-layout-footer>
    </a-layout>
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import {
    getOptionbyTenentId,
    saveOptionAdmin,
  } from '@/api/balance-management/maintenance';
  import { Message } from '@arco-design/web-vue';
  import secretLevelSelect from '@/common/components/cac-components/secret-level-select/index.vue';
  import pageTitle from '@/common/components/title/page-title.vue';
  import Footer from './component/footer.vue';
  import Content from './component/content.vue';

  const form = ref({
    secretLevelValue: '',
  });
  const loading = ref(false);
  const isShow = ref(false);
  const conRef = ref();
  const getOption = async () => {
    try {
      loading.value = true;
      const { data } = await getOptionbyTenentId();
      if (data) {
        form.value.secretLevelValue = data.secretLevel;
        conRef.value.init(data);
      }
    } catch (error) {
      Message.warning({
        content: error,
      });
    } finally {
      loading.value = false;
    }
  };

  const saveData = async () => {
    try {
      loading.value = true;
      const { data } = await saveOptionAdmin({
        ...conRef.value.formCon,
        secretLevel: form.value.secretLevelValue,
      });
      if (data) {
        Message.success('保存成功');
      }
    } catch (error) {
      Message.warning({
        content: error,
      });
    } finally {
      loading.value = false;
    }
  };
  const change = () => {
    console.log(`output->123`, 999);
    conRef.value.init({
      customerTypeOption: 0,
      projectOption: 0,
      materialSameOption: 1,
      procurementPeriodOption: 0,
      aircraftTypeMarkOption: 0,
      batchOption: 0,
      manufactureLotnoOption: 0,
      outSourceDeptOption: 0,
      machiningContentOption: 0,
      taskNoOption: 0,
    });
  };
  onMounted(() => {
    console.log('--------------------2');
    getOption();
  });
</script>
